#include "stream.h"
#include "ui_stream.h"
#include <QFileDialog>
#include <QMessageBox>
#include <rc4.h>
#include <finishatt.h>

Stream::Stream(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Stream)
{
    ui->setupUi(this);

    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(on_pushButton_clicked()));
}

Stream::~Stream()
{
    delete ui;
}

void Stream::on_sourcebutton_clicked()
{
    QString source = QFileDialog::getOpenFileName(this,"open",QCoreApplication::applicationFilePath(),"");
    if(!source.isEmpty()){
        ui->sourcetxtpath->setText(source);
    }


}


void Stream::on_objectivebutton_clicked()
{
    QString objective = QFileDialog::getOpenFileName(this,"open",QCoreApplication::applicationFilePath(),"");
    if(!objective.isEmpty()){
        ui->objectivetxtpath->setText(objective);
    }

}


void Stream::on_pushButton_clicked()
{
    QString sou = ui->sourcetxtpath->toPlainText();//需加密文件地址
    QString obj = ui->objectivetxtpath->toPlainText();//加密后新文件存放的地址
    QString k = ui->keyedit->displayText();

    if(sou.isEmpty())
        QMessageBox::warning(this,"Attention","please choose the source text");
    else if(obj.isEmpty())
        QMessageBox::warning(this,"Attention","please choose the objective text");
    else if(k.isEmpty())
        QMessageBox::warning(this,"Attention","please input the key");
    else{
        Rc4 rc = Rc4(k.toStdString());
        rc.encrypt(sou.toStdString(),obj.toStdString());
        Finishatt *fi = new Finishatt;
        fi->show();
    }
}

